<table id="list" class="scroll"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
<div id="fieldsDialog" title="Category Error">
	<p>
		<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
		Field not selected!<br />
		<b>Please select field for action!</b>
	</p>
</div>

<script type="text/javascript">
jQuery('#list').jqGrid({
	url:'/catalog/fields/list/format/json',
	datatype: 'json',
	mtype: 'GET',
	colNames:['Id', 'Alias', 'Title', 'Field Type'],
	colModel :[
	  {name:'FIELDS_ID', index:'FIELDS_ID', sorttype:'int', width:50},
	  {name:'FIELDS_ALIAS', index:'FIELDS_ALIAS', editable:true, editrules:{required:true}},
	  {name:'FIELDS_TITLE', index:'FIELDS_TITLE', editable:true, editrules:{required:true}},
	  {name:'FIELDS_FIELDTYPE', index:'FIELDS_FIELDTYPE', edittype:'select', editable:true, editrules:{required:true}, editoptions:{value:{<?php foreach ($this->fieldTypes as $id => $title) echo "{$id}:'{$title}',"; ?>}}}],
	pager: jQuery('#pager'),
	rowNum:20,
	rowList:[20, 40, 60, 80, 100, 150, 200],
	sortname: 'FIELDS_ID',
	sortorder: 'asc',
	viewrecords: true,
	caption: 'Fields View',
	editurl: '/catalog/fields/edit',
	height:'auto',
	width:'800'
}).navGrid('#pager',{
	edit:true, add:true, del:true, search:true
}).navButtonAdd('#pager',{
	caption:"Values",
	onClickButton: function(id) {
		var gr = jQuery("#list").getGridParam("selrow");
		if( gr != null ) {
			document.location.href = '/catalog/fields/values/fid/' + gr;
		} else {
			$("#fieldsDialog").dialog('open');
		}
	},
	position:"last"
});

$("#fieldsDialog").dialog({
	bgiframe: true,
	modal: true,
	autoOpen: false,
	buttons: {
		Ok: function() {
			$(this).dialog('close');
		}
	}
});
</script>
